package com.candy.actiivemq.topic;

import lombok.SneakyThrows;
import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * @author: candy
 * @date: 2020/9/20
 * @description :
 **/
public class ProductTopic {

    private final static String URL = "tcp://192.168.0.108:61616";

    @SneakyThrows
    public static void main(String[] args) {
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(URL);
        Connection connection = connectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic myTopic = session.createTopic("MyTopic");
        MessageProducer producer = session.createProducer(myTopic);
        MapMessage mapMessage = session.createMapMessage();
        mapMessage.setString("k1", "v1");
        mapMessage.setString("k2", "v2");
        producer.send(mapMessage);
        producer.close();
        session.close();
        connection.close();

    }
}
